package cn.bitkit.mybatis.query;

import cn.bitkit.base.container.PageRequest;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

/**
 * @author changbo
 */
@Getter
@Setter
@Builder
public class QueryCriteria {

    /** 自定义查询返回的列  **/
    private String select;
    /** 仅连表查询时有效  **/
    private String from;
    /** 分组统计  **/
    private String groupBy;
    /** 排序  **/
    private String orderBy;
    /** 业务参数  **/
    private Object param;
    /** 跳过条数  **/
    private Long offset;
    /** 获取条数  **/
    private Long limit;

    public static QueryCriteria create(Object param){
        return QueryCriteria.builder().param(param).build();
    }

    public static QueryCriteria createPage(PageRequest<?> pageRequest){
        return QueryCriteria.builder().param(pageRequest.getParam())
                .offset(pageRequest.getCurrent()*pageRequest.getSize())
                .limit(pageRequest.getSize())
                .build();
    }

}
